using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreData;
using EntityData;
using Helper;
namespace Services
{

    public partial class Student_ResultService
    {
       readonly IStudent_ResultEntity entity;

       public Student_ResultService()
       {
           this.entity = new Student_ResultEntity();

       }

       #region Main Method

       /// <summary>
       /// Save 
       /// </summary>
       /// <param name="_model"></param>
       /// <returns></returns>
       public long Save(object _model)
       {
           try
           {
               var id = long.Parse(_model.GetType().GetProperty("ID").GetValue(_model, null).ToString());
               if (id == 0)
               {
                   return entity.Save((CoreData.Student_Result)_model, Table.Student_Result.ToString());
               }
               else
               {
                   return entity.Update((CoreData.Student_Result)_model, Table.Student_Result.ToString());
               }
           }
           catch { return -1; }
       }

       /// <summary>
       /// Get by ID
       /// </summary>
       /// <param name="_id"></param>
       /// <returns></returns>
       public CoreData.Student_Result GetByID(long _id)
       {
           try
           {
               return entity.GetByCusTomSQL(String.Format(SQLCommand.GetStudent_Result, "VwStudentResult.ID=" + _id)).ToList()[0];
           }
           catch { return null; }
       }

       /// <summary>
       /// Get by ID
       /// </summary>
       /// <param name="_id"></param>
       /// <returns></returns>
       public CoreData.Student_Result GetByIDResultDetail(long _id)
       {
           try
           {
               return entity.GetByCusTomSQL(String.Format(SQLCommand.GetStudent_ResultDetail, "VwStudentResult.ID=" + _id)).ToList()[0];
           }
           catch { return null; }
       }

       /// <summary>
       /// Get List
       /// </summary>
       /// <returns></returns>
       public IList<CoreData.Student_Result> GetList()
       {
           try
           {
             //  return entity.GetByCusTomSQL(String.Format(SQLCommand.GetStudent_Result, "1=1 and Lock ='false' ")).ToList();
               return entity.GetByCusTomSQL(String.Format(SQLCommand.GetStudent_Result, "1=1 ")).ToList();
           }
           catch { return null; }

       }

       /// <summary>
       /// Get List
       /// </summary>
       /// <returns></returns>
       public IList<CoreData.Student_Result> GetListResultDetail()
       {
           try
           {
               return entity.GetByCusTomSQL(String.Format(SQLCommand.GetStudent_ResultDetail, "1=1")).ToList();
           }
           catch { return null; }

       }


       /// <summary>
       /// Get List with Linq
       /// </summary>
       /// <returns></returns>
       public IList<CoreData.Student_Result> GetListByLINQ(Func<CoreData.Student_Result, Boolean> _where)
       {
           try
           {
               return entity.GetMany(_where, Table.Student_Result.ToString()).ToList();
           }
           catch { return null; }
       }
       /// <summary>
       /// Get One with Linq
       /// </summary>
       /// <returns></returns>
       public CoreData.Student_Result GetOneByLINQ(Func<CoreData.Student_Result, Boolean> _where)
       {
           try
           {
               return entity.Get(_where, Table.Student_Result.ToString());
           }
           catch { return null; }
       }

       /// <summary>
       /// Get List with search string
       /// </summary>
       /// <returns></returns>
       public IList<CoreData.Student_Result> GetList(string _searchstring)
       {
           //search theo tieu chi nao do         
           try
           {
               return entity.GetByCusTomSQL(String.Format(SQLCommand.GetStudent_Result, _searchstring)).ToList();
           }
           catch { return null; }
       }


       /// <summary>
       /// Get List with search string
       /// </summary>
       /// <returns></returns>
       public IList<CoreData.Student_Result> GetListResultDetail(string _searchstring)
       {
           //search theo tieu chi nao do         
           try
           {
               return entity.GetByCusTomSQL(String.Format(SQLCommand.GetStudent_ResultDetail, _searchstring +" Order by SubjectID ")).ToList();
           }
           catch { return null; }
       }

       /// <summary>
       /// Delete
       /// </summary>
       /// <param name="_model"></param>
       /// <returns></returns>
       public bool Delete(object _model)
       {
           try
           {
               entity.Delete((CoreData.Student_Result)_model, Table.Student_Result.ToString());
               return true;
           }
           catch { return false; }
       }


       #endregion



        #region Other Method

       public Student_Result GetByStudentID(long id)
       {
           try
           {
               return entity.GetByCusTomSQL(String.Format(SQLCommand.GetStudent_Result, "VwStudentResult.StudentID=" + id)).ToList()[0];
           }
           catch { return null; }
        }

       public IList<Student_Result> GetBySubjectPointColumnID(long id)
       {
           try
           {
               return entity.GetByCusTomSQL(String.Format(SQLCommand.GetStudent_Result, "VwStudentResult.Subject_PointColumnID=" + id)).ToList();
           }
           catch { return null; }
       }


        #endregion 
    
    }
         
}
